<template>
	<!-- <a-tooltip
		placement="bottom"
		overlayClassName="overlay-tooltip-box"
		class="tooltip-wrap"
		:mouseEnterDelay="0.5"
		:mouseLeaveDelay="0"
	>
		<template slot="title" v-if="item.type === 'Member'">
			<p class="overlay-tooltip-box-name">
				{{ item.$_showLabel }}
			</p>
			<div class="overlay-tooltip-box-label">
				<span class="label-item">岗位：</span> <span class="label-con">{{
					onHandlerPartTimeMember(transItem).postName || '暂无'
				}}</span>
			</div>
			<div class="overlay-tooltip-box-label">
				<span class="label-item">部门：</span> <span class="label-con">{{
					onHandlerPartTimeMember(transItem).deptFullName || '暂无'
				}}</span>
			</div>
		</template>
		<template slot="title" v-else-if="item.type === 'Department'">
			<p class="overlay-tooltip-box-name">
				{{ item.$_showLabel || item.name }}
			</p>
			<div v-if="item.$_postName" class="overlay-tooltip-box-label">
				<span class="label-item">上级：</span>
				<span class="label-con">{{ item.$_postName }}</span>
			</div>
		</template>
		<template slot="title" v-else>
			<p class="overlay-tooltip-box-name">{{ computedTitle(item) }}</p>
		</template> -->
	<span :style="dataFormat.style" :title="setTitle()" class="label-box">{{ dataFormat.label }}</span>
	<!-- </a-tooltip> -->

</template>

<script>
import { entityFormat } from '@/utils/utils';

export default {
	props: ['item'],
	inject: ['app'],
	computed: {
		dataFormat() {
			const orgSelect = this.app().orgSelect;
			const { loginAccountId } = orgSelect;
			const dataFormat = entityFormat(this.transItem, loginAccountId, orgSelect);
			return {
				label: dataFormat.name,
				style: {
					color: dataFormat.color
				}
			};
		},
		/**
		 * 兼容树节点处理
		*/
		transItem() {
			let newItem = this.item;
			if (this.item.data && Object.keys(this.item.data).length) {
				this.item.data.$_showLabel = this.item.data.name;
				newItem = this.item.data;
			}
			return newItem;
		}

	},
	methods: {
		/**
		 * 处理部门人员、岗位人员、职务级别人员兼职的展示处理
		 */
		// onHandlerPartTimeMember(data) {
		// 	let { sourceDepts, sourcePosts } = data;
		// 	if (sourceDepts.length) {
		// 		let deptList = [];
		// 		sourceDepts.forEach((el) => {
		// 			deptList.push(el.name);
		// 		});
		// 		data.deptFullName = deptList.join(',');
		// 		data.deptName = deptList.join(',');
		// 	}
		// 	if (sourcePosts.length) {
		// 		let postList = [];
		// 		sourcePosts.forEach((el) => {
		// 			postList.push(el.name);
		// 		});
		// 		data.postName = postList.join(',');
		// 	}
		// 	return data;
		// },
		// computedTitle(item) {
		// 	let str = `${item.name}\n`;
		// 	if (this.titleProps !== undefined) {
		// 		for (let key in this.titleProps) {
		// 			if (item[key]) {
		// 				str += `${this.titleProps[key]}：${item[key] || ''}\n`;
		// 			}
		// 		}
		// 	}
		// 	return str;
		// }
		setTitle() {
			let entityData = this.transItem;
			console.log('entityData===>', entityData);
			if (entityData.type === 'Member') {
				// return `${entityData.$_showLabel}\n岗位：${entityData.postName || '暂无'}\n部门：${entityData.deptFullName || '暂无'}`;
				return `${entityData.$_showLabel}\n${this.$i18n('common.toolbar.post.label')}：${entityData.postName || this.$i18n('selectPeople.noData')}\n${this.$i18n('selectPeople.department')}：${entityData.deptFullName || this.$i18n('selectPeople.noData')}`;
			} else if (entityData.type === 'Department') {
				let deptFullName = entityData.deptFullName;
				let names = deptFullName.split('/');
				let postName;
				if (names.length <= 1) {
					postName = `${deptFullName}`;
				} else {
					if (names.length > 2) {
						postName = `${names[names.length - 2]}`;
					} else {
						postName = `${entityData.accountShortName}`;
					}
				}
				return `${entityData.name}\n上级：${postName}`;
			} else {
				let str = `${entityData.name}\n`;
				return str;
			}
		}
	},
	created() {
	}
};
</script>
<style scoped lang="scss">
</style>
